// 活动管理 API Service
// 目前使用 mock 数据，后续可以替换为真实 API

class ActivitiesService {
  // 获取活动列表
  async getActivities(params = {}) {
    // 模拟 API 调用
    // 实际使用时替换为: return await fetch('/api/activities', { params })
    const { page = 1, pageSize = 10, status, search } = params;
    
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: {
            list: [],
            total: 0,
            page,
            pageSize
          },
          message: 'success'
        });
      }, 500);
    });
  }

  // 获取单个活动详情
  async getActivityById(id) {
    // 实际使用时替换为: return await fetch(`/api/activities/${id}`)
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: null,
          message: 'success'
        });
      }, 300);
    });
  }

  // 创建活动
  async createActivity(data) {
    // 实际使用时替换为: return await fetch('/api/activities', { method: 'POST', body: JSON.stringify(data) })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { ...data, id: Date.now().toString() },
          message: '活动创建成功'
        });
      }, 500);
    });
  }

  // 更新活动
  async updateActivity(id, data) {
    // 实际使用时替换为: return await fetch(`/api/activities/${id}`, { method: 'PUT', body: JSON.stringify(data) })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { ...data, id },
          message: '活动更新成功'
        });
      }, 500);
    });
  }

  // 删除活动
  async deleteActivity(id) {
    // 实际使用时替换为: return await fetch(`/api/activities/${id}`, { method: 'DELETE' })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: null,
          message: '活动删除成功'
        });
      }, 500);
    });
  }

  // 上线活动
  async publishActivity(id) {
    // 实际使用时替换为: return await fetch(`/api/activities/${id}/publish`, { method: 'POST' })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { id, status: 'published' },
          message: '活动已上线'
        });
      }, 300);
    });
  }

  // 下线活动
  async unpublishActivity(id) {
    // 实际使用时替换为: return await fetch(`/api/activities/${id}/unpublish`, { method: 'POST' })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: { id, status: 'offline' },
          message: '活动已下线'
        });
      }, 300);
    });
  }

  // 上传图片
  async uploadImage(file) {
    // 实际使用时替换为真实的图片上传 API
    return new Promise((resolve) => {
      setTimeout(() => {
        // 创建一个临时的 URL 用于预览
        const url = URL.createObjectURL(file);
        resolve({
          code: 200,
          data: {
            url,
            name: file.name,
            size: file.size
          },
          message: '图片上传成功'
        });
      }, 1000);
    });
  }

  // 批量删除活动
  async batchDeleteActivities(ids) {
    // 实际使用时替换为: return await fetch('/api/activities/batch-delete', { method: 'POST', body: JSON.stringify({ ids }) })
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 200,
          data: null,
          message: `成功删除 ${ids.length} 个活动`
        });
      }, 500);
    });
  }
}

export default new ActivitiesService();